package api

import (
	"api/goods"
	"api/rouquest"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Create(c *gin.Context) {
	var App rouquest.Goods
	if err := c.ShouldBindJSON(&App); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	stu := goods.Goods{
		GoodsId:      App.GoodsId,
		GoodsName:    App.GoodsName,
		GoodsPrice:   App.GoodsPrice,
		GoodsNum:     App.GoodsNum,
		GoodsAddress: App.GoodsAddress,
	}
	err := stu.Creates()
	if err != nil {
		return
	}
	c.JSON(http.StatusOK, gin.H{"data": stu})
}
func ListGoods(c *gin.Context) {
	var App rouquest.Goods
	if err := c.ShouldBindJSON(&App); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	stu := goods.Goods{}
	err := stu.List()
	if err != nil {
		return
	}
	c.JSON(http.StatusOK, gin.H{"data": stu})
}
